import threading
import time

def star_thread(func,client,parser,origin_data,signal):
    stop_event = threading.Event()
    t = threading.Thread(target=func, args=(client,parser,stop_event,origin_data,signal))
    t.start()

    return stop_event


#该线程为处理买家与卖家之间订单同步问题（返回的为所有更新后的数据）（不好）
def seller_request_client(client,parser,stop_event,origin_data,signal):
    count=1
    while not stop_event.is_set():
        time.sleep(2)
        print(f'订单处理第{count}次请求数据')
        count=count+1
        new_data = client.get_orders(parser)
        if new_data != origin_data:
            signal.data_updated.emit(new_data)
            origin_data=new_data

#该线程未处理信息更新
def mes(client,parser,stop_event,origin_data,signal):
    count=1
    while not stop_event.is_set():
        time.sleep(2)
        print(f'消息处理第{count}次请求数据')
        count=count+1
        new_data = client.get_chat(parser).get('data')
        if new_data != origin_data:
            lis=[]
            lis.append(new_data[-1])
            signal.data_updated.emit(lis)
            origin_data=new_data

#向ai提问等待ai回答
def query_ai(client,parser,stop_event,origin_data,signal):

    # time.sleep(5)
    # text = "AI回答测试"
    text=client.query_ai(parser)
    if not stop_event.is_set():
        signal.data_updated.emit(text)

#









